package com.party.web.web.controller.member;

import com.party.common.utils.StringUtils;
import com.party.core.model.commune.CIntegralMedal;
import com.party.core.model.commune.CIntegralType;
import com.party.core.service.commune.ICIntegralMedalService;
import com.party.core.service.commune.ICIntegralTypeService;
import com.party.web.web.dto.AjaxResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.interceptor.TransactionAspectSupport;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @program: party
 * @description: 奖牌控制器
 * @author: Hua Qunhao
 * @create: 2019-08-12 18:56
 **/
@Controller
@RequestMapping("member/integral/integralMedal")
public class IntegralMedalController {

    Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private ICIntegralMedalService integralMedalService;

    @Autowired
    private ICIntegralTypeService integralTypeService;

    /**
     * @Description:奖牌列表
     * @Param:typeId
     * @return:AjaxResult
     * @Author: Hua Qunhao
     * @Date: 2019/8/13
     */
    @ResponseBody
    @RequestMapping("/list")
    public AjaxResult list(String typeId) {
        try {
            if (StringUtils.isEmpty(typeId)) {
                return AjaxResult.error("参数为空");
            }
            CIntegralType cIntegralType = integralTypeService.get(typeId);
            if (cIntegralType == null) {
                logger.error("积分类型不存在");
                return AjaxResult.error("积分类型不存在");
            }
            CIntegralMedal cIntegralMedal = new CIntegralMedal();
            cIntegralMedal.setTypeId(typeId);
            List<CIntegralMedal> list = integralMedalService.list(cIntegralMedal);
            return AjaxResult.success(list);
        } catch (Exception e) {
            logger.error("删除积分类型异常", e);
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
            return AjaxResult.error("删除积分类型异常");
        }
    }
}
